import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class Demo1 {
    public static void main(String[] args) {
        //阻塞队列
        BlockingQueue<Integer> queue = new ArrayBlockingQueue<Integer>(100);
        //生产者
        Thread t1 = new Thread(()->{
            int n = 0;
            while (true){
                System.out.println("生产了:" + n);
                try {
                    queue.put(n);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                n++;
            }
        });
        //消费者
        Thread t2 = new Thread(()->{
        while ( true){
            try {
                int n = queue.take();
                System.out.println("消费了:" + n);
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
        });
        t1.start();
        t2.start();
    }
}
